package me.samlss.lighter_demo.slice;

import me.samlss.lighter.util.LogUtil;
import me.samlss.lighter_demo.ResourceTable;
import me.samlss.lighter_demo.fragment.LighterFragment;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.ability.fraction.FractionManager;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;
import ohos.agp.components.StackLayout;
import ohos.agp.components.Text;
/**
 * @author: zhu_zhonglin
 * @time: 2021/4/25
 */
public class FragmentAbilitySlice extends AbilitySlice {
    private Text title_tv;
    private Image back_iv;
    private StackLayout fragment_content;
    private FractionManager manager;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_fragment);
        initView();
        manager = ((FractionAbility) getAbility()).getFractionManager();
        LogUtil.loge("=== manager" + (manager == null));
        manager.startFractionScheduler().add(ResourceTable.Id_fragment_content, LighterFragment.newInstance()).submit();
    }

    private void initView() {
        title_tv = (Text) findComponentById(ResourceTable.Id_title_tv);
        title_tv.setText("Fragment");
        back_iv = (Image) findComponentById(ResourceTable.Id_back_iv);
        back_iv.setClickedListener(component -> getAbility().terminateAbility());
        fragment_content = (StackLayout) findComponentById(ResourceTable.Id_fragment_content);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
